import 'package:flutter/material.dart';

import 'page1.dart';
import 'page2.dart';

class ClassDetail extends StatefulWidget {
  final content;

  const ClassDetail({Key key, this.content}) : super(key: key);

  @override
  _ClassDetailState createState() => _ClassDetailState();
}

class _ClassDetailState extends State<ClassDetail>
    with SingleTickerProviderStateMixin {
  var titles = ['基本信息', '学时查询'];
  int _currentIndex = 0;
  String title = '';
  List<BottomNavigationBarItem> icons = new List();

  var _controller = PageController(
    initialPage: 0,
  );

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  List<BottomNavigationBarItem> setIcons() {
    icons.clear();
    double iconSize = 20;

    icons.add(BottomNavigationBarItem(
        icon: _currentIndex == 0
            ? Image.asset(
                'images/ic_base_info_s.png',
                height: iconSize,
                width: iconSize,
                fit: BoxFit.fill,
              )
            : Image.asset(
                'images/ic_base_info_un.png',
                height: iconSize,
                width: iconSize,
                fit: BoxFit.fill,
              ),
        title: Text(
          titles[0],
          style: TextStyle(
              color:
                  _currentIndex == 0 ? Color(0xff23AFDC) : Color(0xff999999)),
        )));
    icons.add(BottomNavigationBarItem(
        icon: _currentIndex == 1
            ? Image.asset(
                'images/ic_trans_time_s.png',
                height: iconSize,
                width: iconSize,
                fit: BoxFit.fill,
              )
            : Image.asset(
                'images/ic_trans_time_un.png',
                height: iconSize,
                width: iconSize,
                fit: BoxFit.fill,
              ),
        title: Text(
          titles[1],
          style: TextStyle(
              color:
                  _currentIndex == 1 ? Color(0xff23AFDC) : Color(0xff999999)),
        )));
    return icons;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Color(0xff23AFDC),
        elevation: 0,
        title: Text(titles[_currentIndex]),
        centerTitle: true,
      ),
      body: PageView(
        controller: _controller,
        children: [
          Page1(content: widget.content),
          Page2(content: widget.content)
        ],
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          selectedItemColor: const Color(0xff3e3a39),
          unselectedItemColor: const Color(0xffC3C3C3),
          selectedFontSize: 10,
          unselectedFontSize: 10,
          onTap: (index) {
            title = titles[index];
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });
          },
          type: BottomNavigationBarType.fixed,
          items: setIcons()),
    );
  }
}

//    return Scaffold(
//      appBar: AppBar(
//        backgroundColor: Color(0xff23AFDC),
//        elevation: 0,
//        title: Text('培训日志'),
//        centerTitle: true,
//      ),
//      body: Column(
//        children: <Widget>[
//          SizedBox(height: 21,),
//          SizedBox(
//              height: 87,
//              child: Card(
//                color: Colors.white,
//                shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(18))),
//                elevation: 20,
//                margin: EdgeInsets.symmetric(horizontal: 15),
//                child: Padding(
//                  padding: const EdgeInsets.symmetric(horizontal: 45),
//                  child: Row(
//                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
//                    children: <Widget>[
//                      Column(mainAxisAlignment:MainAxisAlignment.center,children: <Widget>[
//                        Text('dddddddd',style: TextStyle(color: const Color(0xFff5A623),fontSize: 14),),
//                        Text('待培训学时',style: TextStyle(color: const Color(0xFf333333),fontSize: 10),),
//                      ],),
//                      Column(mainAxisAlignment:MainAxisAlignment.center,children: <Widget>[
//                        Text('dddddddd',style: TextStyle(color: const Color(0xFf23AFDC),fontSize: 14),),
//                        Text('累积合格培训学时',style: TextStyle(color: const Color(0xFf333333),fontSize: 10),),
//                      ],),
//                    ],
//                  ),
//                ),
//              )),
//        ],
//      ),
//    );
//  }
//}
